package com.yc.thread.pro3_bestMatching;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zwei
 * @create 2024-07-24 11:17
 */
public class WorldsLoader {
    /**
     * 读取path路径指定的词汇表
     *
     * @param path
     * @return
     */
    public static List<String> load(String path) {
        List<String> data = new ArrayList<>();
        Path file = Paths.get(path);
        try (InputStream iis = Files.newInputStream(file);  //按字节读
             Reader r = new InputStreamReader(iis);           //按字节流转字符，按字节读
             BufferedReader br = new BufferedReader(r)        //可以按行读
        ) {
            String line=null;
            while (   (line=br.readLine())!=null){
                data.add(line);
            }
        }catch ( Exception e){
            e.printStackTrace();
        }
        return data;
    }
}
